package github.sf.fw.tools.db.model;

public class ResultData {
    private String columnName;
    private Object columnValue;
    private int columnType;

    private int columnIndex;

    private Class<?> javaType;

    public String getColumnName() {
        return columnName;
    }

    public void setColumnName(String columnName) {
        this.columnName = columnName;
    }

    public Object getColumnValue() {
        return columnValue;
    }

    public void setColumnValue(Object columnValue) {
        this.columnValue = columnValue;
    }

    public int getColumnType() {
        return columnType;
    }

    public void setColumnType(int columnType) {
        this.columnType = columnType;
    }

    public int getColumnIndex() {
        return columnIndex;
    }

    public void setColumnIndex(int columnIndex) {
        this.columnIndex = columnIndex;
    }

    public Class<?> getJavaType() {
        return javaType;
    }

    public void setJavaType(Class<?> javaType) {
        this.javaType = javaType;
    }

    public String getColumnValueAsString() {
        if (columnValue == null) {
            return null;
        }
        return columnValue.toString();
    }

    public Integer getNumberColumnValue() {
        if (columnValue == null) {
            return 0;
        }
        if (columnValue instanceof Long) {
            return Math.toIntExact((Long) columnValue);
        }
        if (columnValue instanceof Integer) {
            return (Integer) columnValue;
        }
        return 0;
    }

    @Override
    public String toString() {
        return "ResultData{" +
                "columnName='" + columnName + '\'' +
                ", columnValue=" + columnValue +
                ", columnType=" + columnType +
                '}';
    }
}
